#coding:utf-8
import requests
from multiprocessing.dummy import Pool as ThreadPool
import demjson
res = requests.get('http://45.32.100.28:5000/servers',timeout=10)
servers = demjson.decode(res.text)

error = []
success = []
def t(ip):
    try:
        res = requests.get('http://' + ip + '/zmap.txt')
        if res.text.find('zmap: completed')>-1:
            print(ip,'success')
        else:
            print(ip,'wait')
    except Exception as e:
        error.append(ip)
        print(ip,e)
ips = []
for server in servers:
    ips.append(server[1])
pool = ThreadPool(5)
pool.map(t, ips)
pool.close()
pool.join()
print(error)
print(success)
for i,server in enumerate(servers):

    shell = 'wget http://%s/zmap/out.txt -O /var/ipdata/%s.txt' % (server[1],str(i))
    print(shell)
